package com.xiaoxing.zhinenghuacangku_zhijian.mvp.ui.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xiaoxing.zhinenghuacangku_zhijian.R;
import com.xiaoxing.zhinenghuacangku_zhijian.mvp.ui.entity.ChouJianChuKuLieBiao;

import java.util.List;

//import me.jessyan.armscomponent.commonres.utils.GlideUtil;


public class ChouJianChuKuLieBiaoAdapter extends BaseQuickAdapter<ChouJianChuKuLieBiao, BaseViewHolder> {

    private Context mContext;
    private IChouJianChuKuLieBiaoAdapter mIChouJianChuKuLieBiaoAdapter;

    public ChouJianChuKuLieBiaoAdapter(Context context, @Nullable List<ChouJianChuKuLieBiao> data, IChouJianChuKuLieBiaoAdapter iChouJianChuKuLieBiaoAdapter) {
        super(R.layout.item_chou_jian_chu_ku_lie_biao, data);
        this.mContext = context;
        this.mIChouJianChuKuLieBiaoAdapter = iChouJianChuKuLieBiaoAdapter;
    }

    @Override
    protected void convert(BaseViewHolder helper, ChouJianChuKuLieBiao item) {
        //GlideUtil.loadImage(mContext,item.getImg(),helper.getView(R.id.img_head));
        helper.setText(R.id.tv_cang_wei, "仓位: " + item.getSpname());
        helper.setText(R.id.tv_cang_wei_id, "仓位id: " + item.getSpid());
        helper.setText(R.id.tv_chou_jian_shu_liang, "抽检数量: " + item.getSpotnum());
        helper.setText(R.id.tv_ku_cun_shu_liang, "库存数量: " + item.getNums());
        helper.setText(R.id.tv_he_dui_xu_hao, "核对序号: " + item.getMid());
        helper.setText(R.id.tv_zhi_jian_ji_hua_id, "质检计划id: " + item.getMonthid());
        if (item.getIsauto().equals("1")) {
            helper.setText(R.id.tv_shi_fou_zi_dong_ku, "货架类型: 自动货架");
        } else {
            helper.setText(R.id.tv_shi_fou_zi_dong_ku, "货架类型: 人工仓位");
        }
        helper.setText(R.id.tv_qu_yang_wu_liao_ming_cheng, "取样物料名称: " + item.getMaterial());
        helper.setText(R.id.tv_qu_yang_qu, "取样区: " + item.getBuffer_name());
        helper.setText(R.id.tv_qu_yang_qu_id, "取样区id: " + item.getBufferid());
        helper.setText(R.id.tv_cang_ku_ming_cheng, "仓库名称: " + item.getStorename());
        helper.setText(R.id.tv_chou_jian_dan_wei, "抽检单位: " + item.getSpotunit());
        helper.setText(R.id.tv_miao_shu, item.getSpotnum() + item.getSpotunit() + item.getMaterial() + "从" + item.getSpname() + "放至" + item.getBuffer_name());

        Button btn_song_jian = helper.getView(R.id.btn_song_jian);
        Button btn_que_ding = helper.getView(R.id.btn_que_ding);
        if (item.getSendoutorder().equals("0")) {   //sendoutorder=0 则 显示"送检"按钮
            btn_song_jian.setVisibility(View.VISIBLE);
            btn_que_ding.setVisibility(View.GONE);
            helper.setOnClickListener(R.id.btn_song_jian, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mIChouJianChuKuLieBiaoAdapter.songJian(item);
                }
            });
        } else if (item.getSendoutorder().equals("1")) {//sendoutorder=1 则 显示一句话 旁边加个"确认"按钮
            btn_song_jian.setVisibility(View.GONE);
            btn_que_ding.setVisibility(View.VISIBLE);
            helper.setOnClickListener(R.id.btn_que_ding, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mIChouJianChuKuLieBiaoAdapter.queDing(item);
                }
            });
        }


    }

    public interface IChouJianChuKuLieBiaoAdapter {

        void songJian(ChouJianChuKuLieBiao chouJianChuKuLieBiao);

        void queDing(ChouJianChuKuLieBiao chouJianChuKuLieBiao);
    }

}
